#coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from django.db import models

# Create your models here.

class area_manage(models.Model):
    areacode = models.CharField(max_length=10, primary_key=True)
    areaname = models.CharField(max_length=16,verbose_name="区域名称")
    areapinyin = models.CharField(max_length=16,verbose_name="区域拼音")
    def __unicode__(self):
        return self.areacode

class city_manage(models.Model):
    citycode = models.CharField(max_length=10, primary_key=True)
    cityname = models.CharField(max_length=24,verbose_name="城市名称")
    citypinyin = models.CharField(max_length=16,verbose_name="城市拼音")
    areacode =  models.ForeignKey(area_manage)
    coordinates = models.CharField(max_length=24,verbose_name="GPS坐标")

    def __unicode__(self):
        return self.citycode

class backupfile(models.Model):
    citycode = models.CharField(max_length=10)
    source = models.CharField(max_length=16,verbose_name="数据源")
    date=models.BigIntegerField(verbose_name="日期")
    filesize =  models.BigIntegerField(verbose_name="备份文件大小")

    def __unicode__(self):
        return self.source


class updown_cars(models.Model):
    citycode = models.CharField(max_length=10)
    source = models.CharField(max_length=16,verbose_name="数据源")
    date=models.BigIntegerField(verbose_name="日期")
    upcars_nochange =  models.IntegerField(verbose_name="重车未改变状态车辆数")
    downcars_nochange =  models.IntegerField(verbose_name="空车未改变状态车辆数")
    updowncars=models.IntegerField(verbose_name="改变过状态车辆数")
    updwon_change=models.CharField(max_length=20000,verbose_name="切换过状态明细")

    def __unicode__(self):
        return self.source

class updown_cars_detail(models.Model):
    citycode = models.CharField(max_length=10)
    source = models.CharField(max_length=16,verbose_name="数据源")
    date=models.BigIntegerField(verbose_name="日期")
    carid =  models.CharField(max_length=16,verbose_name="车辆ID")
    change_nums =  models.IntegerField(verbose_name="改变状态次数")

    def __unicode__(self):
        return self.carid

class gps_data(models.Model):
    citycode = models.CharField(max_length=10)
    source = models.CharField(max_length=16,verbose_name="数据源")
    date=models.BigIntegerField(verbose_name="日期")
    cars = models.IntegerField(verbose_name="车辆数")
    gps_data = models.IntegerField(verbose_name="GPS量")
    repeats = models.FloatField(max_length=10,verbose_name="重复率")
    interrupt=models.CharField(max_length=200,verbose_name="中断时间")
    interrupt_time=models.IntegerField(verbose_name="中断时间长度")
    def __unicode__(self):
        return self.source

class fusion_yc(models.Model):
    citycode = models.CharField(max_length=10)
    date=models.BigIntegerField(verbose_name="日期")
    host = models.CharField(max_length=20,verbose_name="主机")
    delay=models.IntegerField(verbose_name="延迟个数")
    delay_str = models.CharField(max_length=200,verbose_name="延迟时间段")
    noexist = models.IntegerField(verbose_name="不存在个数")
    noexist_str = models.CharField(max_length=200,verbose_name="不存在时间段")
    version=models.CharField(max_length=12,verbose_name="版本")
    def __unicode__(self):
        return self.citycode

class rh_yc(models.Model):
    citycode = models.CharField(max_length=10)
    date=models.BigIntegerField(verbose_name="日期")
    host = models.CharField(max_length=20,verbose_name="主机")
    delay=models.IntegerField(verbose_name="延迟个数")
    delay_str = models.CharField(max_length=200,verbose_name="延迟时间段")
    noexist = models.IntegerField(verbose_name="不存在个数")
    noexist_str = models.CharField(max_length=200,verbose_name="不存在时间段")
    version=models.CharField(max_length=12,verbose_name="版本")
    def __unicode__(self):
        return self.citycode

class restart(models.Model):
    citycode = models.CharField(max_length=10)
    date=models.BigIntegerField(verbose_name="时间")
    program = models.CharField(max_length=20,verbose_name="程序")
    # delay=models.IntegerField(verbose_name="延迟个数")
    # delay_str = models.CharField(max_length=200,verbose_name="延迟时间段")
    # noexist = models.IntegerField(verbose_name="不存在个数")
    # noexist_str = models.CharField(max_length=200,verbose_name="不存在时间段")
    version=models.CharField(max_length=12,verbose_name="版本")
    def __unicode__(self):
        return self.citycode

class general(models.Model):
    type = models.CharField(max_length=16)
    date=models.BigIntegerField(verbose_name="时间")
    program = models.CharField(max_length=20,verbose_name="程序")
    note=models.CharField(max_length=1200,verbose_name="备注")
    results=models.CharField(max_length=20,verbose_name="备用")
    def __unicode__(self):
        return self.type

class custom_pem(models.Model):
    #
    class Meta:
        permissions = (
            ("ribao", u"日故障统计报表(ribao)"),
            ("index", u"主页(index)"),
            ("interface", u"接口获取(inerface_down)"),
            ("source_total", u"数据源统计(source_total_down)"),
            ("monitor_total", u"报警统计(monitor_total_down)"),
            ("test", u"测试功能(test_down)"),
        )
